

    // Cordova is ready
    //

	
	// PhoneGap加载完毕
	function onDeviceReady() {
		window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
		 /* var db = window.openDatabase("mcdb", "1.0", "myDB", 200000);
        db.transaction(populateDB, errorCB, successCB);*/
	}
	
	// 填充数据库
	function populateDB(tx) {
		 tx.executeSql('DROP TABLE IF EXISTS USERS');
         tx.executeSql('CREATE TABLE IF NOT EXISTS USERS (id unique, phone,userkey)');
         tx.executeSql('INSERT INTO USERS (id, phone,userkey) VALUES (1, '+localStorage.getItem("curphone")+','+localStorage.getItem("userkey")+')');
	}
	
	
	// 事务执行出错后调用的回调函数
	function errorCB(tx,err) {
//		alert("创建错误信息: "+err);
	}
	
	// 事务执行成功后调用的回调函数
	function successCB() {
//		alert("数据表创建成功!");
	}
	
	
	
	
    function gotFS(fileSystem) {
        fileSystem.root.getFile("userkey.txt", {create: true, exclusive: false}, gotFileEntry, fail);
    }

    function gotFileEntry(fileEntry) {
        fileEntry.createWriter(gotFileWriter, fail);
    }

    function gotFileWriter(writer) {
        writer.onwriteend = function(evt) {
            console.log("contents of file now 'some sample text'");
            writer.truncate(11);  
            writer.onwriteend = function(evt) {
                console.log("contents of file now 'some sample'");
                writer.seek(4);
                writer.write("phone:"+localStorage.getItem('curphone')+" userkey:"+localStorage.getItem('userkey'));
                writer.onwriteend = function(evt){
                    console.log("contents of file now 'some different text'");
                }
            };
        };
        writer.write("some sample text");
    }
	
	function init() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS_init, fail);
    }

    function gotFS_init(fileSystem) {
        fileSystem.root.getFile("userkey.txt", {create: true, exclusive: false}, gotFileEntry_init, fail);
    }

    function gotFileEntry_init(fileEntry) {
        fileEntry.createWriter(gotFileWriter_init, fail);
    }

    function gotFileWriter_init(writer) {
        writer.onwriteend = function(evt) {
            console.log("contents of file now 'some sample text'");
            writer.truncate(11);  
            writer.onwriteend = function(evt) {
                console.log("contents of file now 'some sample'");
                writer.seek(4);
                writer.write("phone:null userkey:null");
                writer.onwriteend = function(evt){
                    console.log("contents of file now 'some different text'");
                }
            };
        };
        writer.write("some sample text");
    }
	
	
	
	

    function fail(error) {
        console.log(error.code);
    }

